package com.powernode.controller;

import com.powernode.pojo.Lend;
import com.powernode.service.impl.LendServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 繁寂
 * @version 1.0
 * @since 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/book")
public class LendController {
    private int CurrentId;

    @Autowired
    private LendServiceImpl lendServiceImpl;

    @GetMapping("/selLendAll")
    public List<Lend> selectLendAll(){
        return lendServiceImpl.selLendAll();
    }

    @GetMapping("/selLend/{userName}")
    @ResponseBody
    public List<Lend> selectLend(@Param("userName") String userName){
        return lendServiceImpl.selLendByUserName(userName);
    }

    @PostMapping("/insLend")
    public String insertLend(@RequestBody Lend lend){
        int count = lendServiceImpl.insertLend(lend);
        if(count == 1){
            return  "添加成功";
        }
        return "添加失败";
    }

    @PostMapping("/updLend")
    public String updateLend(@RequestBody Lend lend){
        int count = lendServiceImpl.updateLend(lend);
        if(count == 1){
            return  "更改成功";
        }
        return "更改失败";
    }

    @PostMapping("/delLend")
    public String deleteLend(@RequestBody Lend lend){
        int count = lendServiceImpl.deleteLend(lend);
        if(count == 1){
            return  "删除成功";
        }
        return "删除失败";
    }

    @GetMapping("/getCurrentId/{id}")
    @ResponseBody
    public Integer getCurrentOnceId(@Param("id") int id){
        CurrentId = id;
        return CurrentId;
    }

    @GetMapping("/getCurrentId")
    public Integer sendCurrentId(){
        return CurrentId;
    }


}
